#ifndef AUX_BUFFER_H
#define AUX_BUFFER_H

#include "config.h"
#include "aux_types.h"
#include "aux_errno.h"
#include "aux_thread.h"

typedef enum {
    BUFFER_LOCK_UNKNOWN = 0,
    BUFFER_LOCK_LOCKED,
    BUFFER_LOCK_UNLOCKED,
    BUFFER_LOCK_MAX
} EBufferLockState;

typedef struct {
    u8               abyBuffer[CLIENT_SOCKET_RECV_BUFFER_BYTE_CNT];
    volatile u32     nLength;
    volatile u32     nStart;
    pthread_mutex_t  tMutex;
    EBufferLockState eLockState;
} TxIPCBufferWithLock;

typedef struct {
    u8  abyBuffer[CLIENT_SOCKET_RECV_BUFFER_BYTE_CNT];
    u32 nBufferLength;
} TxIPCBuffer;

EErrNo aux_buf_init_buffer_with_lock(TxIPCBufferWithLock *ptBuf);

EErrNo aux_buf_destroy_buffer_with_lock(TxIPCBufferWithLock *ptBuf);

EErrNo aux_buf_lock(TxIPCBufferWithLock *ptBuf);

EErrNo aux_buf_unlock(TxIPCBufferWithLock *ptBuf);

EErrNo aux_buf_lock_read(TxIPCBufferWithLock *ptBuf,
                                         u8  *pabyData,
                                         u32 *pnLen);

EErrNo aux_buf_lock_append(TxIPCBufferWithLock *ptBuf,
                                           u8  *pabyData,
                                           u32  nLen);

EErrNo aux_buf_lock_get_size(TxIPCBufferWithLock *ptBuf,
                                            u32 *pnLen);

#endif
